
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/head.ftl">
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu = "systemmessages"/>
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">系统信息管理</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/systemmessages/list.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入昵称/邮箱">
                </div>
                <div class="form-group">
                    <label>用户搜索:</label>
                    <select class="form-control" name="userId">
                        <option value="-1">请选择</option>
                        <#list users.list as s>
                            <option value="${s.id}">${s.nickName}</option>
                        </#list>
                    </select>
                    <script>
                        $("select[name=userId]").val(${qo.userId!})
                    </script>
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success addBtn" id="addBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加系统消息
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>内容</th>
                    <th>是否已读</th>
                    <th>创建时间</th>
                    <th>目标用户</th>
                    <th>操作</th>
                </tr>

                <#list pageInfo.list as u>
                <#--遍历查询得到的每一个domain对象-->
                    <tr>
                        <td>${u.content!}</td>
                        <td>${u.stateName!}</td>
                        <td>${u.createTime?string("yyyy-MM-dd")!}</td>
                        <td>${u.author.nickName!}</td>
                        <td>
                            <a role="button" class="inputBtn" data-json='${u.json}'>修改</a>
                            |
                            <a role="button" class="deleteBtn" data-json='${u.json}'>删除</a>
                        </td>
                    </tr>
                </#list>

            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<div id="systemMessagesModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/systemmessages/save" style="margin: -3px 118px">
                    <input id="systemMessagesId" type="hidden" name="id"/>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">消息</label>
                        <textarea name="content" id="content"></textarea>
                    </div>

                    <div class="form-group" id="author">
                        <div>
                            <label class="control-label" style="margin-left: 60px">用户：</label>
                        </div>
                        <div class="row" style="margin-top: 10px">

                                <div class="col-sm-5">
                                    <select multiple class="form-control" size="15" name="ids" id="allName">
                                        <#list users.list as s>
                                            <option value="${s.id}">${s.nickName}</option>
                                        </#list>
                                    </select>
                                </div>

                            <div class="col-sm-2" style="margin-top: 60px;" align="center">
                                <div >
                                    <a type="button" class="btn btn-info  "  style="margin-top: 10px"
                                       onclick="moveSelected('allName', 'selfName')">&nbsp;&gt;&nbsp;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveSelected('allName', 'selfName')">&nbsp;&lt;&nbsp;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveAll('allName', 'selfName')">&gt;&gt;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveAll('selfName', 'allName')">&lt;&lt;</a>
                                </div>
                            </div>
                            <div class="col-sm-5">
                                <select multiple class="form-control selfPermissions" size="15" name="ids" id="selfName">

                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function(){
        //删除方法
        $(".deleteBtn").click(function () {
            var json = $(this).data("json");
            $.get("/systemmessages/delete.do",{id:json.id},function (data) {
                if (data.success){
                    window.location.reload()
                }else {
                    alert(data.msg)
                }
            })
        })
        //添加方法
        $("#addBtn").click(function () {
            $("#systemMessagesModal").modal("show")
        })
        //提交表单
        $("#saveBtn").click(function () {
            $("#selfName option").prop("selected",true)
            $("#editForm").ajaxSubmit(function (data) {
                if(data.success){
                    window.location.reload()
                }else {
                    alert(data.msg)
                }
            });
        })

    });
    //列表移动
    function moveSelected(a, b) {
        $("#" + a + " option:selected").appendTo("#" + b);
    }

    function moveAll(a, b) {
        $("#" + a + " option").appendTo("#" + b);
    }
</script>
</html>